package org.example.system.controller;

import org.example.commons.vo.ResultVO;
import org.example.system.service.ISysFeedbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * author 陈伯瑞
 * date 2020/6/15 0015 21:37
 * version 1.0
 **/
@RestController
@RequestMapping("/api/system/data")
public class MessageAnalysis {
    /**
     *消息数据分析
     *
     */
    @Autowired
    private ISysFeedbackService feedbackService;
    /* 返回所有的用户数量*/
    @GetMapping("/num")
    public ResultVO analysis()  {
        return  ResultVO.success(feedbackService.queryAll().size());
    }

    /* 返回最近天数的用户数量*/
    @GetMapping("/ByDay")
    public Number dataByDay(@RequestParam("days") Integer days) {
        return  feedbackService.queryLastFeedBydays(days).size();
    }

    /*返回最近三十天和上个三十天的数据*/
    @GetMapping("/Bymonth")
    public ResultVO dataBymonth() {
        Map map=new HashMap();
        List<Integer> data = new ArrayList<Integer>();
        data.add(feedbackService.queryLastFeedBydays(24).size());
        data.add(feedbackService.queryLastFeedBydays(18).size());
        data.add(feedbackService.queryLastFeedBydays(12).size());
        data.add(feedbackService.queryLastFeedBydays(6).size());
        data.add(feedbackService.queryLastFeedBydays(0).size());
        map.put("newData",data);

        List<Integer> datal = new ArrayList<Integer>();
        datal.add(feedbackService.queryLastFeedBydays(49).size());
        datal.add(feedbackService.queryLastFeedBydays(43).size());
        datal.add(feedbackService.queryLastFeedBydays(37).size());
        datal.add(feedbackService.queryLastFeedBydays(31).size());
        datal.add(feedbackService.queryLastFeedBydays(25).size());
        map.put("oldData",datal);
        return ResultVO.success(map);
    }

}
